<?php

declare(strict_types=1);

namespace Modules\Inventory\Models;

use Illuminate\Database\Eloquent\Relations\HasMany;
use Modules\Base\Models\Material;
use Modules\Warehouse\Models\Stash;
use Catch\Base\CatchModel as Model;

class InventoryPlanDiff extends Model
{

    protected $table = 'inventory_plan_diff';

    protected $fillable = [ 'id','org_code','cargo_code','plan_id','docno','wms_code','material_no','unit','qty','diff_type','creator_id','created_at','updated_at','deleted_at'];

    /**
     * @var array
     */
    protected array $fields = ['id','org_code','cargo_code','plan_id','docno','wms_code','material_no','unit','qty','diff_type','creator_id','created_at','updated_at','deleted_at'];

    /**
     * @var array
     */
    protected array $form = ['id','org_code','cargo_code','plan_id','docno','wms_code','material_no','unit','qty','diff_type','creator_id','created_at','updated_at','deleted_at'];

    /**
     * @var array
     */
    public array $searchable = [

    ];

    public function getFields(){
        return $this->fields;
    }

    /**
     * 返回产品信息
     * @return HasMany
     */
    public function material()
    {
        return $this->hasOne(Material::class,'fnumber','material_no');
    }

    /**
     * 关联仓库信息
     * @return mixed
     */
    public function wms(){
        return $this->hasOne(Stash::class,'fnumber','wms_code');
    }

    /**
     * 时间格式化
     * @param $date
     * @return mixed
     */
    protected function serializeDate($date)
    {
        return $date->format('Y-m-d H:i');
    }

}
